package factory;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

//Requires all options under to be selected

/**
 * @author Steve
 * RequiredMenu class.  All items under this menu must be selected
 */
public class RequiredMenu extends LoadableMenu{

	/**
	 * @param args 
	 * @param input
	 */
	public RequiredMenu(LinkedList<String> args, Scanner input){ 
		super(args, input); 
	}

	/** 
	 * removes and returns OrderObject item
	 * @return OrderObject or item in list
	 */
	@Override
	public OrderObject getOrder(Scanner in){
		OrderObject[] items = new OrderObject[options.size()];

		ArrayList<LoadableMenu> tempOptions = new ArrayList<LoadableMenu>(options);
		ArrayList<String> choices = new ArrayList<String>();
		for(LoadableMenu lm : options)
			choices.add(lm.name);


		while(choices.size() > 0){
			System.out.println("\nSelecting a " + name);
			System.out.println("\nPlease select the next option.");

			int selection = presentMenu(choices, in);

			items[choices.size()-1] = tempOptions.get(selection).getOrder(in); // getSelection

			choices.remove(selection);
			tempOptions.remove(selection);
		}		
		return new OrderObject(name, price, display, items);
	}
}
